home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
WINDOWS
/
WIN_MORT.ARJ
/
WINMORT.CPP
< prev
next >
Wrap
Text File
|
1992-01-12
|
4KB
|
189 lines
/* WINMORT.CPP
*
* Description: Basic Mortgage Calculator for Windows 3.0
*
* Author: Robert H. Kornberg
* Date: 1-03-91
*
*/
#include <stdio.h> // Standard "C" header files
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <owl.h> // Object Windows Header Files
#include <edit.h>
#include <static.h>
#include "moneycl.h" // Header file for the MONEYCL class
#include "winmort.h" // Header FIle containing Resource Ids
#define PRINSIZE 18
#define TERMSIZE 3
#define RATESIZE 7
#define POINTSIZE 7
#define PAYSIZE 18
#define APRSIZE 7
typedef struct { // Dialog Box Transfer Buffer
char principle[PRINSIZE];
char term[TERMSIZE];
char rate[RATESIZE];
char points[POINTSIZE];
char payment[PAYSIZE];
char apr[APRSIZE];
} MortFields;
// Main window containing the calculator fields
_CLASSDEF(TMortCalc)
class TMortCalc : public TDialog
{
MoneyCl MonthlyAmt, Principle;
double Rate, Points, APR;
int Term;
MortFields *FormData;
PTEdit PPrinciple;
PTStatic PMonPay, PAPR;
public:
TMortCalc (PTWindowsObject AParent);
~TMortCalc();
virtual LPSTR GetClassName();
virtual void ProcessPrinciple(RTMessage Msg) = [ID_FIRST + id_Principle];
virtual void CalcMonthlyAmount() = [ID_FIRST + id_CalcBtn];
virtual void ClearAll() = [ID_FIRST + id_ClearBtn];
virtual void CalcAmounts();
virtual double Mort();
};
TMortCalc::TMortCalc(PTWindowsObject AParent) : TDialog(AParent, MAKEINTRESOURCE(DIAG_MORTCALC))
{
PPrinciple = new TEdit (this, id_Principle, PRINSIZE);
new TEdit (this, id_Term, TERMSIZE);
new TEdit (this, id_Rate, RATESIZE);
new TEdit (this, id_Points, POINTSIZE);
PMonPay = new TStatic (this, id_Monthly, PAYSIZE);
PAPR = new TStatic (this, id_APR, APRSIZE);
FormData = new MortFields;
memset (FormData, 0, sizeof(MortFields));
TransferBuffer = FormData;
PMonPay->EnableTransfer();
PAPR->EnableTransfer();
}
TMortCalc::~TMortCalc()
{
delete (PPrinciple);
delete (PMonPay);
delete (PAPR);
delete (FormData);
}
void TMortCalc::ClearAll()
{
memset (FormData, 0, sizeof(MortFields));
TransferData (TF_SETDATA);
PostMessage (HWindow, WM_NEXTDLGCTL, PPrinciple->HWindow, 1);
}
LPSTR TMortCalc::GetClassName()
{
return "BorDlg";
}
void TMortCalc::CalcMonthlyAmount()
{
TransferData (TF_GETDATA);
Principle.SetValue( FormData->principle );
Rate = atof (FormData->rate)/100.0;
Points = atof (FormData->points)/100.0;
Term = atoi (FormData->term);
APR = Rate;
CalcAmounts();
strcpy(FormData->payment, MonthlyAmt.MoneyStr());
sprintf(FormData->apr, "%.2lf", APR);
TransferData (TF_SETDATA);
PostMessage (HWindow, WM_NEXTDLGCTL, PPrinciple->HWindow, 1);
}
void TMortCalc::CalcAmounts()
{
Points *= Principle.MoneyVal();
MonthlyAmt.SetValue(Mort());
Principle.SetValue( Principle.MoneyVal() - Points );
double test, testpay, ifp;
test = Rate;
for (ifp = test; ifp <= 0.25; ifp += 0.0001)
{
APR = ifp;
testpay = Mort();
if (testpay >= MonthlyAmt.MoneyVal())
break;
}
APR *= 100.0;
}
double TMortCalc::Mort()
{
return Principle.MoneyVal()/((1-pow(1+APR/12,-1*Term*12))/(APR/12));
}
void TMortCalc::ProcessPrinciple(RTMessage Msg)
{
if ( Msg.LP.Lo != 0 )
if ( Msg.LP.Hi == EN_KILLFOCUS)
{
char tempPrin[MONEYSIZE];
PPrinciple->GetText(tempPrin, MONEYSIZE);
Principle.SetValue(tempPrin);
PPrinciple->SetText ( Principle.MoneyStr());
}
}
// Standard OWL Application Class
class TMortApp : public TApplication
{
public:
TMortApp(LPSTR AName, HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
: TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
virtual void InitMainWindow();
};
void TMortApp::InitMainWindow()
{
MainWindow = new TMortCalc(NULL);
}
// Program Entry Point
int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
TMortApp PApp("Mortgage Calculator", hInstance, hPrevInstance,
lpCmdLine, nCmdShow);
PApp.Run();
return PApp.Status;
}